package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.TestDateService;
import com.itheima.service.TestMemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/prerecord")
public class TestDateController {
@Reference
    private TestDateService testDateService;
@Reference
   private TestMemberService testMemberService;
@RequestMapping("/noDate")
    public Result nosetDate(HttpServletRequest res,@RequestBody Map<String,Object> map)throws Exception{
    String telephone=null;
    for (Cookie cookie : res.getCookies()) {
        String value = cookie.getValue();
        telephone=value;
    }
    Member member = testMemberService.findMember(telephone);
    Integer id = member.getId();
    map.put("id",id);
    List<Map<String, Object>> objectMap = testDateService.setDateFind(map);
    return new Result(true, MessageConstant.TEST_MEMBER_SUCCESS,objectMap);
}
@RequestMapping("/autoDate")
    public Result autoDate(HttpServletRequest res)throws Exception{
    String telephone=null;
    for (Cookie cookie : res.getCookies()) {
        String value = cookie.getValue();
        telephone=value;
    }

    Member member = testMemberService.findMember(telephone);
    Integer id = member.getId();
    List<Map<String, Object>> maps = testDateService.setAutoDateFind(id);
    return new Result(true,MessageConstant.TEST_MEMBER_SUCCESS,maps);
}
}
